New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid using _PS_PRICE_COMPUTE_PRECISION_ #26824
Conversation
Hello @mpaolino! This is your first pull request on the PrestaShop project. Thank you, and welcome to this Open Source community! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR ! As I said in #26553 the PR seems good but we really need a list of clear steps to reproduce the bug, else QA team wont be able to reproduce the issue and verify it's now solved.
Actually there is more than one bug in that single conditional line.The problem why QA could not reproduce it was probably they didn't made a purchase that was higher or equals to $1000. The rationale behind that comparison is they are trying to avoid rounding errors, but:
php > var_dump(number_format(1000, 2));
string(8) "1,000.00"
php > var_dump(number_format(1000, 0));
string(5) "1,000"
php > var_dump(number_format(100, 2));
string(6) "100.00"
php > var_dump(number_format(100, 0));
string(3) "100" This is how PHP prior to 8.0 does the comparison on number strings: https://www.php.net/manual/en/language.operators.comparison.php So for example: php > var_dump(number_format(1000, 2) != number_format(1000, 0));
bool(true)
php > var_dump(number_format(100, 2) != number_format(100, 0));
bool(false)
php > var_dump(number_format(100, 2) != number_format(100.10, 0));
bool(false) There are a number of ways of doing this right but probably PHPs strcmp will work correctly independently of all combinations, I will update this if I have the time. |
@matks done. Steps to reproduce in bug report. |
Hello, I just tested the change in the PaymentModule.php file and it no longer throws a payment error with the bank transfer module in Colombia currency without decimals. https://drive.google.com/file/d/1-6ESV_2R6voEnkq3kv4fIg5MkkT6kCRF/view?usp=sharing Thanks, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix seems good. Can you rebase 1.7.8.x and change the PR target ?
I can help if you need it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mpaolino
…mp to avoid conversion errors while doing comparisons
Change strcmp for strict inequality operator for amount string comparison Co-authored-by: Jonathan Lelievre <jo.lelievre@gmail.com>
Hi @mpaolino , please notice that that the same constant is being used in another place of the same file: Could you change that one too to avoid another PR? |
Hi. I already pointed that out in the initial PR report. This is a bug fix for a single reported bug, what your are asking here is that I complete the refactor of PaymentModule to completely remove the constant. Although I recognize there must be another underlying bug there, this is out of scope for this PR and I don't have the time to hunt for the triggering use cases. Feel free to provide the PR as it will require a different set of test instructions. |
@sowbiba I assume there is something required from me since the issue is in "Waiting for author". Can you comment on that? |
Any news to be able to mix the PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @mpaolino
Tested on 1.7.8.x branch.
PHP 7.2.21 version
Tested on cases below:
- created order from BO with product > 1000 + < 1000
- created order from FO with product > 1000 + < 1000
- tested with custom currencies with decimal/without decimal
- tested with custom currencies with modified exchange rate
- tested with multiple payment modules
- modified order statuses options
QA approved ✅
Thanks @mpaolino |
Thanks to everyone |
_PS_PRICE_COMPUTE_PRECISION_
to generate a string representation of the total amount paid with a payment module and comparing that to the cart total string representation calculated withContext::getContext()->getComputingPrecision()
. This check will always fail when a currency with a decimal precision is different than the present_PS_PRICE_COMPUTE_PRECISION_ = 2
constant, hence the order will be placed in a payment error status and no log or further details will be displayed. This happens for example while using MercadoPago payment module v4.8.0 (official partner). Apparently PS_PRICE_COMPUTE_PRECISION was deprecated in 1.7.7.x but this core class still uses it. The proposed change substitutes the constant with the precision value obtained from the context, just like it is used in the rest of the source code. Also a log is added to register this error situation._PS_PRICE_COMPUTE_PRECISION_
is in use in PaymentModule, this should be probably addressed in a different issue.This change is